package com.damon.jdbc;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.damon.utils.DbUtil;

/**
 * 调用存储过程
 * @author 风蚕
 *
 */
public class ExecutorProcedureJdbc {
	private static Logger logger = LoggerFactory.getLogger(ExecutorProcedureJdbc.class);
	
	
	public static String doProceduce(String procedureName,String param ) {
		Connection connection = null;
		String result = null;
		try {
			connection = DbUtil.getConnection();
			String sql2 = "{call " + procedureName + "(?,?)}";
			CallableStatement statement = connection.prepareCall(sql2);
			statement.setString(1, param);
			statement.registerOutParameter(2, Types.VARCHAR);
			statement.execute();
			result = statement.getString(2);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("调用存储过程失败！存储过程名："+procedureName+",参数："+param);
		}finally {
			try {
				connection.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		
		return result;
	}
}
